#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time: 2022/12/21 18:11
# @Author: hekang
# @Email: 591785757@qq.com
# @File：knowledge_page.py
"""
知识页
"""
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from pages.base_page import BasePage


class Knowledge(BasePage):
    # 定位器
    search_include_locator = (  # 定位"包含"下拉框
        By.ID, "condition")
    search_true_locator = (  # 定位"是"
        By.CSS_SELECTOR, "#condition > option:nth-child(2)")
    search_inputBox_locator = (  # 定位搜索的输入框
        By.CSS_SELECTOR, "#search")
    search_locator = (  # 定位"搜索"按钮
        By.CSS_SELECTOR, "#dosearch")

    # 点击"包含"下拉框选择"是"
    def search_include(self):
        search_element = self.driver.find_element(*self.search_include_locator)  # 将函数解构传入变量
        including = Select(search_element)  # 类的实例化
        including.select_by_value("is")  # 选择“是”

    # 搜索输入框输入内容
    def search_input(self, SearchBox):
        self.driver.find_element(*self.search_inputBox_locator).send_keys(SearchBox)

    # 点击搜索
    def search(self):
        self.driver.find_element(*self.search_locator).click()
